﻿#region using

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

#endregion

namespace JupiterLibrary
{
    /// <summary>
    /// Contiene información sobre un clip
    /// </summary>
    public class Clip
    {
        public Texture_2D Texture;
        public int Number;

        public Clip(Texture_2D texture, int number)
        {
            Texture = texture;
            Number = number;
        }

        /// <summary>
        /// Devuelve el rectángulo del lugar donde está el clip en la textura de clips
        /// </summary>
        /// <returns></returns>
        public Rectangle GetSourceRect()
        {
            return Texture.GetClip(Number);
        }

        public void Draw(Vector2 position, SpriteBatch sprite)
        {
            Draw(new Point((int)position.X, (int)position.Y), sprite, Color.White, false);
        }

        public void Draw(Point position, SpriteBatch sprite)
        {
            Draw(position, sprite, Color.White, false);
        }

        public void Draw(Point position, SpriteBatch sprite, Color color, bool flipX)
        {
            Rectangle src = GetSourceRect();

            Rectangle destination = src;

            destination.Location = position;

            if (flipX)
                sprite.Draw(Texture.Texture, destination, src, color, 0, Vector2.Zero, SpriteEffects.FlipHorizontally, 0);
            else
                sprite.Draw(Texture.Texture, destination, src, color);
        }

    }
}
